<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="盒子id" prop="boxId">
          <el-input
            v-model="queryParams.boxId"
            placeholder="请输入盒子id"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="userId" prop="userId">
          <el-input
            v-model="queryParams.userId"
            placeholder="请输入userId"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡id" prop="card1Id">
          <el-input
            v-model="queryParams.card1Id"
            placeholder="请输入第一张卡id"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡名称" prop="card1Name">
          <el-input
            v-model="queryParams.card1Name"
            placeholder="请输入第一张卡名称"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡图片" prop="card1Img">
          <el-input
            v-model="queryParams.card1Img"
            placeholder="请输入第一张卡图片"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡点数 1-6" prop="card1Points">
          <el-input
            v-model="queryParams.card1Points"
            placeholder="请输入第一张卡点数 1-6"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡位置 1-12" prop="card1Index">
          <el-input
            v-model="queryParams.card1Index"
            placeholder="请输入第一张卡位置 1-12"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第一张卡抽卡时间" prop="card1Time">
          <el-date-picker clearable
            v-model="queryParams.card1Time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择第一张卡抽卡时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="第二张卡id" prop="card2Id">
          <el-input
            v-model="queryParams.card2Id"
            placeholder="请输入第二张卡id"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第二张卡名称" prop="card2Name">
          <el-input
            v-model="queryParams.card2Name"
            placeholder="请输入第二张卡名称"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第二张卡图片" prop="card2Img">
          <el-input
            v-model="queryParams.card2Img"
            placeholder="请输入第二张卡图片"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第二张卡点数 1-6" prop="card2Points">
          <el-input
            v-model="queryParams.card2Points"
            placeholder="请输入第二张卡点数 1-6"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第二张卡位置 1-12" prop="card2Index">
          <el-input
            v-model="queryParams.card2Index"
            placeholder="请输入第二张卡位置 1-12"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第二张卡抽卡时间" prop="card2Time">
          <el-date-picker clearable
            v-model="queryParams.card2Time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择第二张卡抽卡时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="第三张卡id" prop="card3Id">
          <el-input
            v-model="queryParams.card3Id"
            placeholder="请输入第三张卡id"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第三张卡名称" prop="card3Name">
          <el-input
            v-model="queryParams.card3Name"
            placeholder="请输入第三张卡名称"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第三张卡图片" prop="card3Img">
          <el-input
            v-model="queryParams.card3Img"
            placeholder="请输入第三张卡图片"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第三张卡点数 1-6" prop="card3Points">
          <el-input
            v-model="queryParams.card3Points"
            placeholder="请输入第三张卡点数 1-6"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第三张卡位置 1-12" prop="card3Index">
          <el-input
            v-model="queryParams.card3Index"
            placeholder="请输入第三张卡位置 1-12"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="第三张卡抽卡时间" prop="card3Time">
          <el-date-picker clearable
            v-model="queryParams.card3Time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择第三张卡抽卡时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="门票价值" prop="tickets">
          <el-input
            v-model="queryParams.tickets"
            placeholder="请输入门票价值"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="中奖返还百分比" prop="proportion">
          <el-input
            v-model="queryParams.proportion"
            placeholder="请输入中奖返还百分比"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="回收价值" prop="recyclingPrice">
          <el-input
            v-model="queryParams.recyclingPrice"
            placeholder="请输入回收价值"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="奖品id" prop="prizeId">
          <el-input
            v-model="queryParams.prizeId"
            placeholder="请输入奖品id"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="奖品名称" prop="prizeName">
          <el-input
            v-model="queryParams.prizeName"
            placeholder="请输入奖品名称"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="奖品图片" prop="prizeImg">
          <el-input
            v-model="queryParams.prizeImg"
            placeholder="请输入奖品图片"
            clearable
            
          />
        </el-form-item>
        <el-form-item label="奖品是否在保险柜 0-否 1-是" prop="insurance">
          <el-input
            v-model="queryParams.insurance"
            placeholder="请输入奖品是否在保险柜 0-否 1-是"
            clearable
            
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:record:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:record:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:record:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:record:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="${comment}" align="center" prop="id" />
        <el-table-column label="盒子id" align="center" prop="boxId" />
        <el-table-column label="userId" align="center" prop="userId" />
        <!-- <el-table-column label="第一张卡id" align="center" prop="card1Id" />
        <el-table-column label="第一张卡名称" align="center" prop="card1Name" />
        <el-table-column label="第一张卡图片" align="center" prop="card1Img" /> -->
        <el-table-column label="第一张卡点数 1-6" align="center" prop="card1Points" />
        <!-- <el-table-column label="第一张卡位置 1-12" align="center" prop="card1Index" /> -->
        <el-table-column label="第一张卡抽卡时间" align="center" prop="card1Time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.card1Time, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="第二张卡id" align="center" prop="card2Id" />
        <el-table-column label="第二张卡名称" align="center" prop="card2Name" />
        <el-table-column label="第二张卡图片" align="center" prop="card2Img" /> -->
        <el-table-column label="第二张卡点数 1-6" align="center" prop="card2Points" />
        <!-- <el-table-column label="第二张卡位置 1-12" align="center" prop="card2Index" /> -->
        <el-table-column label="第二张卡抽卡时间" align="center" prop="card2Time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.card2Time, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="第三张卡id" align="center" prop="card3Id" />
        <el-table-column label="第三张卡名称" align="center" prop="card3Name" />
        <el-table-column label="第三张卡图片" align="center" prop="card3Img" /> -->
        <el-table-column label="第三张卡点数 1-6" align="center" prop="card3Points" />
        <!-- <el-table-column label="第三张卡位置 1-12" align="center" prop="card3Index" /> -->
        <el-table-column label="第三张卡抽卡时间" align="center" prop="card3Time" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.card3Time, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="门票价值" align="center" prop="tickets" />
        <el-table-column label="中奖返还百分比" align="center" prop="proportion" />
        <el-table-column label="回收价值" align="center" prop="recyclingPrice" />
        <el-table-column label="奖品id" align="center" prop="prizeId" />
        <el-table-column label="奖品名称" align="center" prop="prizeName" />
        <el-table-column label="奖品图片" align="center" prop="prizeImg" >
          <template slot-scope="scope">
            <el-image :src="scope.row.prizeImg" style="width: 80px; height: 90px" />
          </template>
        </el-table-column>
        <el-table-column label="奖品是否在保险柜" align="center" prop="insurance" >
          <template slot-scope="scope">
          <el-tag v-if="scope.row.insurance == 0">否</el-tag>
          <el-tag v-if="scope.row.insurance == 2" type="success">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status" >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 1">已中奖</el-tag>
            <el-tag v-if="scope.row.status == 2" type="success">待发货</el-tag>
            <el-tag v-if="scope.row.status == 3" type="warning">已发货</el-tag>
            <el-tag v-if="scope.row.status == 4" type="danger">已收货</el-tag>
            <el-tag v-if="scope.row.status == 5" type="info">已回收</el-tag>
 
            <el-tag v-if="scope.row.status == 0" type="info">进行中</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:record:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:record:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改【请填写功能名称】对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="盒子id" prop="boxId">
            <el-input v-model="form.boxId" placeholder="请输入盒子id" />
          </el-form-item>
          <el-form-item label="userId" prop="userId">
            <el-input v-model="form.userId" placeholder="请输入userId" />
          </el-form-item>
          <el-form-item label="第一张卡id" prop="card1Id">
            <el-input v-model="form.card1Id" placeholder="请输入第一张卡id" />
          </el-form-item>
          <el-form-item label="第一张卡名称" prop="card1Name">
            <el-input v-model="form.card1Name" placeholder="请输入第一张卡名称" />
          </el-form-item>
          <el-form-item label="第一张卡图片" prop="card1Img">
            <el-input v-model="form.card1Img" placeholder="请输入第一张卡图片" />
          </el-form-item>
          <el-form-item label="第一张卡点数 1-6" prop="card1Points">
            <el-input v-model="form.card1Points" placeholder="请输入第一张卡点数 1-6" />
          </el-form-item>
          <el-form-item label="第一张卡位置 1-12" prop="card1Index">
            <el-input v-model="form.card1Index" placeholder="请输入第一张卡位置 1-12" />
          </el-form-item>
          <el-form-item label="第一张卡抽卡时间" prop="card1Time">
            <el-date-picker clearable
              v-model="form.card1Time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择第一张卡抽卡时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="第二张卡id" prop="card2Id">
            <el-input v-model="form.card2Id" placeholder="请输入第二张卡id" />
          </el-form-item>
          <el-form-item label="第二张卡名称" prop="card2Name">
            <el-input v-model="form.card2Name" placeholder="请输入第二张卡名称" />
          </el-form-item>
          <el-form-item label="第二张卡图片" prop="card2Img">
            <el-input v-model="form.card2Img" placeholder="请输入第二张卡图片" />
          </el-form-item>
          <el-form-item label="第二张卡点数 1-6" prop="card2Points">
            <el-input v-model="form.card2Points" placeholder="请输入第二张卡点数 1-6" />
          </el-form-item>
          <el-form-item label="第二张卡位置 1-12" prop="card2Index">
            <el-input v-model="form.card2Index" placeholder="请输入第二张卡位置 1-12" />
          </el-form-item>
          <el-form-item label="第二张卡抽卡时间" prop="card2Time">
            <el-date-picker clearable
              v-model="form.card2Time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择第二张卡抽卡时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="第三张卡id" prop="card3Id">
            <el-input v-model="form.card3Id" placeholder="请输入第三张卡id" />
          </el-form-item>
          <el-form-item label="第三张卡名称" prop="card3Name">
            <el-input v-model="form.card3Name" placeholder="请输入第三张卡名称" />
          </el-form-item>
          <el-form-item label="第三张卡图片" prop="card3Img">
            <el-input v-model="form.card3Img" placeholder="请输入第三张卡图片" />
          </el-form-item>
          <el-form-item label="第三张卡点数 1-6" prop="card3Points">
            <el-input v-model="form.card3Points" placeholder="请输入第三张卡点数 1-6" />
          </el-form-item>
          <el-form-item label="第三张卡位置 1-12" prop="card3Index">
            <el-input v-model="form.card3Index" placeholder="请输入第三张卡位置 1-12" />
          </el-form-item>
          <el-form-item label="第三张卡抽卡时间" prop="card3Time">
            <el-date-picker clearable
              v-model="form.card3Time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择第三张卡抽卡时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="门票价值" prop="tickets">
            <el-input v-model="form.tickets" placeholder="请输入门票价值" />
          </el-form-item>
          <el-form-item label="中奖返还百分比" prop="proportion">
            <el-input v-model="form.proportion" placeholder="请输入中奖返还百分比" />
          </el-form-item>
          <el-form-item label="回收价值" prop="recyclingPrice">
            <el-input v-model="form.recyclingPrice" placeholder="请输入回收价值" />
          </el-form-item>
          <el-form-item label="奖品id" prop="prizeId">
            <el-input v-model="form.prizeId" placeholder="请输入奖品id" />
          </el-form-item>
          <el-form-item label="奖品名称" prop="prizeName">
            <el-input v-model="form.prizeName" placeholder="请输入奖品名称" />
          </el-form-item>
          <el-form-item label="奖品图片" prop="prizeImg">
            <el-input v-model="form.prizeImg" placeholder="请输入奖品图片" />
          </el-form-item>
          <el-form-item label="奖品是否在保险柜 0-否 1-是" prop="insurance">
            <el-input v-model="form.insurance" placeholder="请输入奖品是否在保险柜 0-否 1-是" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/ppl/jl.js";
  
  export default {
    name: "Record",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        recordList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          boxId: null,
          userId: null,
          card1Id: null,
          card1Name: null,
          card1Img: null,
          card1Points: null,
          card1Index: null,
          card1Time: null,
          card2Id: null,
          card2Name: null,
          card2Img: null,
          card2Points: null,
          card2Index: null,
          card2Time: null,
          card3Id: null,
          card3Name: null,
          card3Img: null,
          card3Points: null,
          card3Index: null,
          card3Time: null,
          tickets: null,
          proportion: null,
          recyclingPrice: null,
          prizeId: null,
          prizeName: null,
          prizeImg: null,
          insurance: null,
          status: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          boxId: [
            { required: true, message: "盒子id不能为空", trigger: "blur" }
          ],
          userId: [
            { required: true, message: "userId不能为空", trigger: "blur" }
          ],
          card1Name: [
            { required: true, message: "第一张卡名称不能为空", trigger: "blur" }
          ],
          card1Img: [
            { required: true, message: "第一张卡图片不能为空", trigger: "blur" }
          ],
          card2Name: [
            { required: true, message: "第二张卡名称不能为空", trigger: "blur" }
          ],
          card2Img: [
            { required: true, message: "第二张卡图片不能为空", trigger: "blur" }
          ],
          card3Name: [
            { required: true, message: "第三张卡名称不能为空", trigger: "blur" }
          ],
          card3Img: [
            { required: true, message: "第三张卡图片不能为空", trigger: "blur" }
          ],
          insurance: [
            { required: true, message: "奖品是否在保险柜 0-否 1-是不能为空", trigger: "blur" }
          ],
          createTime: [
            { required: true, message: "$comment不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listRecord(this.queryParams).then(response => {
          this.recordList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          boxId: null,
          userId: null,
          card1Id: null,
          card1Name: null,
          card1Img: null,
          card1Points: null,
          card1Index: null,
          card1Time: null,
          card2Id: null,
          card2Name: null,
          card2Img: null,
          card2Points: null,
          card2Index: null,
          card2Time: null,
          card3Id: null,
          card3Name: null,
          card3Img: null,
          card3Points: null,
          card3Index: null,
          card3Time: null,
          tickets: null,
          proportion: null,
          recyclingPrice: null,
          prizeId: null,
          prizeName: null,
          prizeImg: null,
          insurance: null,
          status: 0,
          createTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getRecord(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改【请填写功能名称】";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateRecord(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addRecord(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
          return delRecord(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/record/export', {
          ...this.queryParams
        }, `record_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  